#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define MAX_SIZE 100000

typedef struct QQ
{
    bool have;
    char num[11];
    char pwd[17];

} All_QQ[MAX_SIZE];

All_QQ DataSet;

int Check(char *QQ, char *pwd, int size);
int Create(char *QQ, char *pwd, int size);
int Hash(char *QQ, int N);
int MPrime(int n);
int main()
{
    char cmd='\n', QQ_num[11], pwd[17];
    int flag;
    int N, MSize;
    scanf("%d\n", &N);
    MSize = MPrime(N);
    for (int i = 0; i < MAX_SIZE;i++)
        DataSet[i].have = false;
    
    for (int i = 0; i < N; i++)
    {
        while(cmd == '\n')
            scanf("%c", &cmd);
        if (cmd == 'L') //login in
        {
            scanf("%s %s", &QQ_num, &pwd);
            flag = Check(QQ_num, pwd, MSize);
            switch (flag)
            {
            case 1:
                printf("Login: OK\n");
                break;
            case 2:
                printf("ERROR: Wrong PW\n");
                break;
            case 3:
                printf("ERROR: Not Exist\n");
                break;
            default:
                printf("error\n");
                break;
            }
        }
        else if(cmd == 'N')//create new
        {
            scanf("%s %s", &QQ_num, &pwd);
            flag = Create(QQ_num, pwd, MSize);
            switch(flag)
            {
                case 1:
                    printf("New: OK\n");
                    break;
                case 2:
                    printf("ERROR: Exist\n");
                    break;
                default:
                    printf("error\n");
                    break;
            }
        }
        cmd = '\n';
}    
        
    return 0;
}
int Create(char *QQ, char *pwd, int size)
{
    int hash_num = Hash(QQ, size);
    if(!DataSet[hash_num].have)
    {
        strcpy(DataSet[hash_num].num, QQ);
        strcpy(DataSet[hash_num].pwd, pwd);
        DataSet[hash_num].have = true;
        return 1;
    }
    else if(strcmp(pwd, DataSet[hash_num].pwd) == 0)
        return 2;
}
int Check(char *QQ, char *pwd, int size)
{
    int hash_num = Hash(QQ, size);
    if(!DataSet[hash_num].have)
        return 3;
    else if(DataSet[hash_num].have)
    {
        if(strcmp(pwd, DataSet[hash_num].pwd) == 0)
            return 1;
        else
            return 2;
    }
}
int Hash(char *QQ, int N)
{
    long unsigned int tail = atoi(QQ);
    int hash_num;
    for (int i = 0; i < N;i++)
    {
        hash_num = (tail + i) % N;
        if(!DataSet[hash_num].have)
            return hash_num;
        else if(strcmp(QQ, DataSet[hash_num].num) == 0)
            return hash_num;
    }
    return -1;
}

//求素数
int MPrime(int n)
{
    //最小的情况需要考虑 最小素数为 2
    if (n == 1)
        return 2;

    n--;//把n包含进来
    int i, p = (n % 2) ? n + 2 : n + 1;//下一个奇数开始
    while (1)
    {
        for (i = (int)sqrt(p); i > 2; i--)
            if (!(p % i))
                break;
        if(i==2)
            break;
        else
            p += 2;
    }
    return p;
}